package com.example.swagger.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Locale;

/**
 * 全面扩展springmvc
 *
 * WebMvcConfigurer是接口类，实现
 */
@Configuration
//如果你想自定义一些定制化的功能，只要写这个组件，把它交给springboot，springboot就会帮我们自动装配
public class MyMVCConfig implements WebMvcConfigurer {

//    public interface ViewResolve 实现了视图解析器的类，我们就可以把它看作视图解析器

//    public ViewResolver myViewReslover(){
//        return myViewReslover();
//    }
//    //自定义一个视图解析器
//    public static class MyViewReslover implements ViewResolver {
//
//        @Override
//        public View resolveViewName(String viewName, Locale locale) throws Exception {
//            return null;
//        }
//    }
//如果要扩展springmvc，官方建议我们这样做
    @Override
    public void addViewControllers(ViewControllerRegistry registry){
        registry.addViewController("/test").setViewName("test");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/login.html","/","users/login");
    }
}
